<div class="layuimini-main" style="padding-left: 40px">

    <div class="layui-form layui-form-pane">

        <fieldset class="layui-elem-field layui-field-title">
            <legend>Config 设置</legend>
        </fieldset>


        <div class="layui-form-item">
            <label class="layui-form-label">设置页</label>
            <div class="layui-input-block">
                <input type="text" name="config_type" lay-verify="required" lay-reqtext="不能为空"  value="" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">Title</label>
            <div class="layui-input-block">
                <input type="text" name="config_title" lay-verify="required" lay-reqtext="标题不能为空"  value="" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">Keywords</label>
            <div class="layui-input-block">
                <input type="text" name="config_keywords" lay-verify="required" lay-reqtext="不能为空"  value="" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label required">Description</label>
            <div class="layui-input-block">
                <textarea name="config_description" class="layui-textarea" lay-verify="required" placeholder="长度不超过200个字符"></textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['form', 'iconPickerFa','upload','miniUpload'], function () {
        var form = layui.form,
            layer = layui.layer,
            miniUpload = layui.miniUpload,
            $ = layui.$;
        var miniPage = layui.miniPage;

        // 当前弹出层，防止ID被覆盖
        var parentIndex = layer.index;
        /**
         * 初始化表单，要加上，不然刷新部分组件可能会不加载
         */
        form.render();
        // 上传图片
        miniUpload.uploadImg('img_src', 'upload_img_demo');

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            layer.load(2);
            $.ajax({
                url: 'config',
                method: 'POST',
                data: data.field,
                success: function (res) {
                    layer.closeAll('loading');
                    if (res.code === 0) {
                        layer.msg('保存成功', {icon: 1}, function () {
                            layer.close(parentIndex);
                            // 刷新列表
                            var options = {};
                            options.homeInfo = options.homeInfo || {};
                            miniPage.refresh(options);
                        })
                    } else {
                        layer.msg(res.msg, {icon: 5})
                    }
                },
                error: function (res) {
                    layer.msg('请求错误', {icon: 5})
                }
            });
            return false;
        });

    });
</script>
